package com.ctshk.rpc.bus.service.impl;

import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctshk.common.dto.Result;
import com.ctshk.common.exception.BusinessException;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.service.support.BaseService;
import com.ctshk.rpc.bus.dto.BusInitializationSettingsDTO;
import com.ctshk.rpc.bus.entity.BusInitializationSettings;
import com.ctshk.rpc.bus.mapper.BusInitializationSettingsMapper;
import com.ctshk.rpc.bus.req.BusInitializationSettingsReq;
import com.ctshk.rpc.bus.service.IBusInitializationSettingsService;

/**
 * <p>
 * 巴士票api初始化设置表 服务实现类
 * </p>
 *
 * @author 彭柳霖
 * @since 2021-02-07
 */
@DubboService
public class BusInitializationSettingsServiceImpl extends ServiceImpl<BusInitializationSettingsMapper, BusInitializationSettings> implements IBusInitializationSettingsService, BaseService {

	@Autowired
	BusInitializationSettingsMapper busInitializationSettingsMapper;
	
    /**
     * 保存巴士票api设置
     *
     * @param busInitializationSettingsReq
     */
    @Transactional(rollbackFor = BusinessException.class)
    @Override
    public Result<Void> saveSettingInfo(BusInitializationSettingsReq req, TokenUser user) {
        BusInitializationSettings entity = busInitializationSettingsMapper.selectOneByKey("supplier_id", req.getSupplierId());
        
        //新增
        if (entity == null) {
        	entity = newCreateEntity(BusInitializationSettings.class, req, user);
        	busInitializationSettingsMapper.insert(entity);
        } else {  //修改
        	entity = fillUpdateEntity(entity, req, user);
        	busInitializationSettingsMapper.updateById(entity);
        }
        
        return newResult();
    }


    /**
     * 查询巴士票api设置
     *
     * @param supplierId
     * @return
     */
    @Override
    public BusInitializationSettingsDTO queryDetail(Long supplierId) {
    	return busInitializationSettingsMapper.selectOneByKey(BusInitializationSettingsDTO.class, "supplier_id", supplierId);
    }
}
